<!--#include file="asp-common-cop.asp"-->
<!--#include file="asp-common-custom.asp"-->
<%
'错误信息
Set dError=Server.CreateObject("Scripting.Dictionary")
dError.add "1","未找到数据"
dError.add "2","没有权限"
dError.add "3","没有登录"
dError.add "4","输入不能为空"

'表格信息
Set dTable=Server.CreateObject("Scripting.Dictionary")
dTable.add "cd","报关单"
dTable.add "htmlfile","预录单(WEB)"
dTable.add "tzhtml","海关通知单(WEB)"
dTable.add "edocfile","随附单据(PDF)"
dTable.add "username","用户"

'核销单状况
Set dStatus=Server.CreateObject("Scripting.Dictionary")
dStatus.add "1","未退"
dStatus.add "2","海关已退"
dStatus.add "3","已退客户"

'是否
Set dBool=Server.CreateObject("Scripting.Dictionary")
dBool.add "True","是"
dBool.add "False","否"

' 权限字典
Set dAuthority=Server.CreateObject("Scripting.Dictionary")
dAuthority.add "1","查询"
dAuthority.add "2","查询、查看"
dAuthority.add "3","查询、查看、添加"
dAuthority.add "4","查询、查看、添加、编辑"
dAuthority.add "5","查询、查看、添加、编辑、删除"
dAuthority.add "15","管理员"

Set dCdTable=Server.CreateObject("Scripting.Dictionary")
dCdTable.add "wtr_name","委托人"
dCdTable.add "bwtr_name","被委托人"
dCdTable.add "category_name","类型"
dCdTable.add "cd_no","报关单号"
dCdTable.add "cd_date","申报日期"
dCdTable.add "cd_company","企业名称"
dCdTable.add "cd_voyage","船名航次"
dCdTable.add "cd_lading","提单号"
dCdTable.add "cd_verify","核销单号"
dCdTable.add "cd_passno","通关单号"
dCdTable.add "cd_orderno","合同号"
dCdTable.add "cd_boxno","箱数(TEU)"
dCdTable.add "cd_memo","备注"
dCdTable.add "cd_status","核销单状况"
dCdTable.add "cd_statusdate","核销单日期"
dCdTable.add "cd_confirm","确认"
dCdTable.add "cd_receive","报关费(应收)"
dCdTable.add "cd_pay","报关费(应付)"
dCdTable.add "total_receive","合计(应收)"
dCdTable.add "total_pay","合计(应付)"
dCdTable.add "cd_actreceive","实际(已收)"
dCdTable.add "cd_actpay","实际(已付)"
dCdTable.add "post","岗位"

' npedi字典
Set dNpedi=Server.CreateObject("Scripting.Dictionary")
dNpedi.add "1","集装箱进门"
dNpedi.add "2","提单详细信息"
dNpedi.add "3","码头进门信息"
dNpedi.add "4","海关移箱指令信息"
dNpedi.add "5","集装箱海关放行信息"
dNpedi.add "6","集装箱出门"
dNpedi.add "7","出口装船"
dNpedi.add "8","海关布/解控信息"
dNpedi.add "9","集装箱国际中转综合"
dNpedi.add "10","进口卸船"
dNpedi.add "11","国检查验作业流动情况"
dNpedi.add "12","集装箱堆存"
dNpedi.add "13","出口集装箱综合信息"
dNpedi.add "14","集装箱转场综合"
dNpedi.add "15","单箱历史"
dNpedi.add "16","进口集装箱综合信息"
dNpedi.add "17","镇司/大榭E港区集装箱堆存"
dNpedi.add "18","智能闸口CLP状态"
dNpedi.add "19","海关闸口放行"
dNpedi.add "20","集卡作业历史"
dNpedi.add "21","双信息出口装船放行"
dNpedi.add "22","集装箱陆路物流"
dNpedi.add "23","海关分拨箱"
dNpedi.add "24","海关新舱单回执"
dNpedi.add "25","码头预配信息"
dNpedi.add "26","内支线中转(乍浦到宁波)"
dNpedi.add "27","在场集装箱信息"


'代替ASP中的Request函数，可以对一切的SQL注入Say NO
Function SafeRequest(ParaName,ParaType)
'--- 传入参数 ---
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字，0表示以上参数为字符)
  Dim ParaValue
  ParaValue=Request(ParaName)
  If ParaType=1 then
    If Not IsNumeric(ParaValue) then
      Response.Write "参数" & ParaName & "必须为数字型！"
      Response.End
    End If
  Else
    ParaValue=Replace(ParaValue,"'","''")
  End If
  SafeRequest=ParaValue
End Function

function srequest(ParaName,ParaType)
'--- 传入参数 ---
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字，0表示以上参数为字符)
'用在request中对id字段的判断
    Dim ParaValue
    ParaValue=Request(ParaName)
    If ParaType=1 then
        Dim RegExpObj
        Set RegExpObj=new RegExp
        RegExpObj.Pattern="^[1-9]\d*|0$"
        if not RegExpObj.test(ParaValue) then
            Response.Write "参数" & ParaName & "必须为整数！"
            Response.End
        End If
        Set RegExpObj=nothing
    Else
        ParaValue=Replace(ParaValue,"'","''")
    End If
  srequest=ParaValue
end function




function ULen(byval str)
  Dim RegExpObj,ReGCheck
  Set RegExpObj=new RegExp
  RegExpObj.Pattern="^[\u4e00-\u9fa5|\uFF00-\uFFFF]+$"
  Dim l,t,c,i
  l=Len(str)
  t=l
  For i=1 to l
    c=Mid(str,i,1)
    ReGCheck=RegExpObj.test(c)
    If ReGCheck Then
      t=t+1
    End If
  Next
  Set RegExpObj=nothing
  ULen=t
end function

function FillSpace(str,len)
    dim u
    u=ULen(str)
    if u mod 2 <>0 then
        str=str&" "
        u=u+1
    end if
    FillSpace=str&String((len-u)/2,"　")
end function

'执行command对象函数，sql_text为要执行的sql语句，return_id为是否要返回insert后的自动编号
function ExecuteCommand(sql_text,return_id)
  dim last_id,cmd,rs_last
  set cmd=Server.CreateObject("ADODB.Command")
  cmd.ActiveConnection = conn
  cmd.CommandText = sql_text
  ' response.write(sql_text)
  ' response.end
  cmd.Execute
  if lcase(left(ltrim(sql_text),6))="insert" and return_id then
    cmd.CommandText = "select @@IDENTITY"
    set rs_last=cmd.Execute
    last_id=rs_last.getstring
    rs_last.close
    set rs_last=nothing
  end if
  set cmd=nothing
  ExecuteCommand=last_id
end function




'检查登录用户是否在这个岗位
function CheckPost(aaTemp,iPost)
  dim i
  CheckPost=false
  if iPost="" then exit function
  if not IsArray(aaTemp) then exit function
  for i=0 to ubound(aaTemp,2)
    if aaTemp(0,i)=clng(iPost) then
      CheckPost=true
      exit function
    end if
  next
end function

'检查登录用户是否有权限，只要有任何一个岗位低于iFlag，就返回false
function CheckFlag(aaTemp,iFlag)
  dim i
  CheckFlag=false
  if not CheckLogin() then
    call JumpErrorPage(3)
    exit function
  end if
  if iFlag="" then exit function
  if not IsArray(aaTemp) then exit function
  for i=0 to ubound(aaTemp,2)
    if aaTemp(1,i)<clng(iFlag) then exit function
  next
  CheckFlag=true
end function

'检查登录用户是否有某个岗位的某个权限
function CheckOnlyPostFlag(aaTemp,iPost,iFlag)
  CheckOnlyPostFlag=false
  if not CheckLogin() then
    exit function
  end if
  if iPost="" or iFlag="" then exit function
  if not IsArray(aaTemp) then exit function
  if GetFlagValue(aaTemp,iPost)>=clng(iFlag) then
    CheckOnlyPostFlag=true
  end if
end function


'检查登录用户是否有某个岗位的某个权限
function CheckPostFlag(aaTemp,iPost,iFlag)
  CheckPostFlag=false
  if not CheckLogin() then
    call JumpErrorPage(3)
    exit function
  end if
  if iPost="" or iFlag="" then exit function
  if not IsArray(aaTemp) then exit function
  if GetFlagValue(aaTemp,iPost)>=clng(iFlag) then
    CheckPostFlag=true
  end if
end function

'获取某个岗位的权限
function GetFlagValue(aaTemp,iPost)
  dim i
  GetFlagValue=0
  if iPost="" then exit function
  if not IsArray(aaTemp) then exit function
  for i=0 to ubound(aaTemp,2)
    if aaTemp(0,i)=clng(iPost) then
      GetFlagValue=clng(aaTemp(1,i))
      exit function
    end if
  next
end function

'获得权限的中文字符
' function GetFlagString(iFlag)
  ' select case iFlag
    ' case 1 GetFlagString="查询"
    ' case 2 GetFlagString="查询、查看"
    ' case 3 GetFlagString="查询、查看、添加"
    ' case 4 GetFlagString="查询、查看、添加、编辑"
    ' case 5 GetFlagString="查询、查看、添加、编辑、删除"
    ' case 15 GetFlagString="管理员"
    ' case else GetFlagString=""
  ' end select
' end function

'获得岗位的中文字符
' function GetPostString(iPost)
  ' select case iPost
    ' case 0 GetPostString="用户权限"
    ' case 1 GetPostString="输入"
    ' case 2 GetPostString="作业"
    ' case 3 GetPostString="审核"
    ' case 4 GetPostString="财务"
    ' case 5 GetPostString="核销单管理"
    ' case else GetPostString=""
  ' end select
' end function



'获得岗位的中文字符
function GetPostString(aaTemp,iPost)
  dim i
  GetPostString=""
  if not IsArray(aaTemp) then exit function
  for i=0 to ubound(aaTemp,2)
    if aaTemp(0,i)=clng(iPost) then
      GetPostString=aaTemp(1,i)
      exit function
    end if
  next
end function


'判断是否是：不等于空字符串并且不等于0的数字
function IsNumberNz(s)
  IsNumberNz=false
  if IsNumeric(s) then
    if s<>"" and s<>0 then
      IsNumberNz=true
    end if
  end if
end function

'跳转到错误页面，id是错误编号，url是跳转前的页面地址
function JumpErrorPage(iError)
  dim oldurl
  oldurl="http://"&request.ServerVariables("HTTP_HOST")&request.ServerVariables("Url")
  if request.ServerVariables("QUERY_STRING")<>"" then oldurl=oldurl&"?"&request.ServerVariables("QUERY_STRING")
  response.redirect("error.asp?id="&iError&"&url="&Server.URLEncode(oldurl))
end function

function ShowError(iError)
  response.write("错误："&dError(cstr(iError)))
  response.end
end function

function CheckLogin()
  CheckLogin=false
  ' if session("sSystem")="yongding" and session("bLogin")=true then CheckLogin=true
  if session("bLogin")=true then CheckLogin=true
end function


' function CheckLogin_Wtr()
  ' CheckLogin_Wtr=false
  ' if session("sSystem")="yongding" and session("bLogin")=true and session("bEmployee")=false then CheckLogin_Wtr=true
' end function

function CheckWtr()
  if not session("bEmployee") then CheckWtr=true else CheckWtr=false
end function

function CheckEmployee()
  if session("bEmployee") then CheckEmployee=true else CheckEmployee=false
end function

' 判断用户访问的httphost地址，因为如果判断用户ip，可能是用vpn拨号进来的，那就可能是10.8.2这段，会误判
function CheckLan()
  CheckLan=false
  if request.ServerVariables("HTTP_HOST")="192.168.0.253" or request.ServerVariables("HTTP_HOST")="127.0.0.1" or request.ServerVariables("HTTP_HOST")="localhost" then CheckLan=true
end function

function CheckBoxNo(sBoxNo)
  CheckBoxNo=false
  Dim RegExpObj
  Set RegExpObj=new RegExp
  RegExpObj.Pattern="^[A-Z]{4}\d{7}$"
  CheckBoxNo=RegExpObj.test(sBoxNo)
  Set RegExpObj=nothing
end function

function CheckPassword(sPassword)
  CheckPassword=false
  Dim RegExpObj
  Set RegExpObj=new RegExp
  RegExpObj.Pattern="^(?![^a-zA-Z]+$)(?!\D+$).{6,}$"
  CheckPassword=RegExpObj.test(sPassword)
  Set RegExpObj=nothing
end function

function OperateClient(iUser)
  dim rs_client,sql_client
  set rs_client=server.createobject("adodb.recordset")
  sql_client="select * from client where clientip='"&Request.ServerVariables("remote_addr")&"' and clientagent='"&Request.ServerVariables("http_user_agent")&"'"
  if iUser="null" then sql_client=sql_client&" and username is null" else sql_client=sql_client&" and username="&iUser
  
  rs_client.open sql_client,conn,1,1
  if not rs_client.eof and not rs_client.bof then
    OperateClient=rs_client("id")
  else
    OperateClient=ExecuteCommand("insert into client(username,clientip,clienthost,clientagent) values("&iUser&",'"&Request.ServerVariables("remote_addr")&"','"&Request.ServerVariables("remote_host")&"','"&Request.ServerVariables("http_user_agent")&"')",true)
  end if
  rs_client.close
  set rs_client=nothing
end function


function SimpleRecord(re_table,re_id,re_operate,re_memo,username,re_clientid,return_id)
  dim sql
  ' if re_id="null" then sql="insert into record(re_table,re_operate,re_memo,username,re_clientid) values('"&lcase(re_table)&"','"&re_operate&"','"&re_memo&"',"&username&","&re_clientid&")" else sql="insert into record(re_table,re_id,re_operate,re_memo,username,re_clientid) values('"&lcase(re_table)&"',"&re_id&",'"&re_operate&"','"&re_memo&"',"&username&","&re_clientid&")"
  sql="insert into record(re_table,re_id,re_operate,re_memo,username,re_clientid) values('"&lcase(re_table)&"',"&re_id&",'"&re_operate&"','"&re_memo&"',"&username&","&re_clientid&")"
  if return_id then
    SimpleRecord=ExecuteCommand(sql,true)
  else
    call ExecuteCommand(sql,false)
  end if
end function

'==================================================================  
'函数：FormatTime   
'功能：日期时间格式化   
'参数：DateTime,日期时间   
'Template,格式化模板   
'返回：格式化后的字串   
'备注：模板标签注释   
'　　　{Y}:年   
'　　　{y}:2位年   
'　　　{M}:月   
'　　　{m}:补位月，例：01,02   
'　　　{ME}:英文月份   
'　　　{Me}:英文月份缩写   
'　　　{D}:日   
'　　　{d}:补位日   
'　　　{H}:时   
'　　　{h}:补位时   
'　　　{N}:分   
'　　　{n}:补位分   
'　　　{S}:秒   
'　　　{s}:补位秒   
'　　　{W}:星期几英文   
'　　　{w}:星期几英文缩写     
'==================================================================  
  
Function FormatTime(DateTime,Template)   
    If (Not IsDate(DateTime)) or Template = "" Then  
        FormatTime = Template   
        Exit Function  
    End If  
    Dim dtmY,dtmM,dtmD,dtmH ,dtmN,dtmS,dtmW   
    Dim arrFW,arrSW,arrFM,arrSM   
    dtmY = Year(DateTime)   
    dtmM = Month(DateTime)   
    dtmD = Day(DateTime)   
    dtmH  = Hour(DateTime)   
    dtmN = Minute(DateTime)   
    dtmS = Second(DateTime)   
    dtmW = WeekDay(DateTime)   
    arrFW = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")   
    arrSW = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")   
    arrFM = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")   
    arrSM = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")     
    Template = Replace(Template,"{Y}",dtmY)   
    Template = Replace(Template,"{y}",Right(dtmY,2))   
    Template = Replace(Template,"{M}",dtmM)   
    Template = Replace(Template,"{m}",Right("00"&dtmM,2))   
    Template = Replace(Template,"{ME}",arrFM(dtmM-1))   
    Template = Replace(Template,"{Me}",arrSM(dtmM-1))   
    Template = Replace(Template,"{D}",dtmD)   
    Template = Replace(Template,"{d}",Right("00"&dtmD,2))   
    Template = Replace(Template,"{H}",dtmH )   
    Template = Replace(Template,"{h}",Right("00"&dtmH ,2))   
    Template = Replace(Template,"{N}",dtmN)   
    Template = Replace(Template,"{n}",Right("00"&dtmN,2))   
    Template = Replace(Template,"{S}",dtmS)   
    Template = Replace(Template,"{s}",Right("00"&dtmS,2))   
    Template = Replace(Template,"{W}",arrFW(dtmW-1))   
    Template = Replace(Template,"{w}",arrSW(dtmW-1))   
    FormatTime = Template   
End Function



%>
